package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysUserJobService;
import com.seahorse.youliao.service.entity.SysUserJobDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysUserJobQueryVO;
import com.seahorse.youliao.vo.response.SysUserJobPageInfoVO;
import com.seahorse.youliao.vo.response.SysUserJobResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 用户与岗位关联表
* @author : songqiang
* @date: 2020-01-17 09:23:46.367
**/
@RestController
@Api("SysUserJobController")
@RequestMapping("sysUserJob")
@Validated
public class SysUserJobController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysUserJobController.class);
    
	@Autowired
    private SysUserJobService sysUserJobService;
    /**
     * 分页查询
     * @param sysUserJobQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysUserJobPageInfoVO selectPageList(@RequestBody @Valid SysUserJobQueryVO sysUserJobQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysUserJobQueryVO.toString());
        LOGGER.info(info);
        SysUserJobDTO sysUserJob = BeanUtil.convert(sysUserJobQueryVO, SysUserJobDTO.class);

        Page<SysUserJobResponseVO> page = PageHelper.startPage(sysUserJobQueryVO.getPageNum(), sysUserJobQueryVO.getPageSize());
        List<SysUserJobDTO> sysUserJobList = sysUserJobService.getList(sysUserJob);
        SysUserJobPageInfoVO sysUserJobPageInfo = new SysUserJobPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysUserJobPageInfo);
        List<SysUserJobResponseVO> voList = BeanUtil.convert(sysUserJobList, SysUserJobResponseVO.class);
        sysUserJobPageInfo.setList(voList);

        return sysUserJobPageInfo;
    }


}
